package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.RecordCapacityAnalysis;
import com.water_work_form.entity.RecordSpectrophotometric;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.RecordSpectrophotometricService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * <p>
 * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-09-14
 */
@RestController
@RequestMapping("/record-spectrophotometric")
public class RecordSpectrophotometricController {

    @Autowired
    RecordSpectrophotometricService recordSpectrophotometricService;

    /**
     * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 项目新增
     * @param recordSpectrophotometric 新数据
     * @return 返回对应code 0为成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addRecordSpectrophotometric(@RequestBody RecordSpectrophotometric recordSpectrophotometric){
        recordSpectrophotometric.setId(RandomIdUtil.createRandomId());
        recordSpectrophotometricService.save(recordSpectrophotometric);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, recordSpectrophotometric);
    }

    /**
     * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 项目查看（2个查询项+分页）
     * @param checkStartDate 检测日期（check_date）范围查询开始日期
     * @param checkEndDate 检测日期（check_date）范围查询结束日期
     * @param checkSite 检测地点（check_site）查询项
     * @param current 分页查看 当前页数
     * @param size 分页查看 每页最大数据量
     * @return 返回符合上述条件的数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listRecordSpectrophotometric(@RequestParam("checkStartDate") String checkStartDate, @RequestParam("checkEndDate") String checkEndDate,
                                               @RequestParam("checkSite") String checkSite, @RequestParam("status") String status, @RequestParam("current") Integer current,
                                               @RequestParam("size") Integer size){
        IPage<RecordSpectrophotometric> page = recordSpectrophotometricService.selectRecordSpectrophotometric(checkStartDate, checkEndDate, checkSite, status, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 项目删除
     * @param id 需要删除的项目对应的id
     * @return 返回对应code 0为成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteRecordSpectrophotometric(@RequestParam("id") Long id){
        recordSpectrophotometricService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 项目更新
     * @param recordSpectrophotometric 需要更新的项目
     * @return 返回对应code 0为成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateRecordSpectrophotometric(@RequestBody RecordSpectrophotometric recordSpectrophotometric){
        recordSpectrophotometricService.updateById(recordSpectrophotometric);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 基础表数据查询
     * @param formName form表name
     * @param type device表type
     * @param name1 restriction表name，formula表name，curve表name，curve_preparation表name，drug表name
     * @param name2 restriction表name，formula表name，curve表name，curve_preparation表name，drug表name
     * @param name3 restriction表name，formula表name，curve表name，curve_preparation表name，drug表name
     * @param name4 restriction表name，formula表name，curve表name，curve_preparation表name，drug表name
     * @param name5 restriction表name
     * @param waterId water表id
     * @param volume volume表name
     * @return 返回所有查询到的数据
     */
    @ApiOperation("基础表数据查询")
    @GetMapping("/basicList")
    public Result listBasicSpectrophotometric( @RequestParam("formName") String formName, @RequestParam("type") String type, @RequestParam("name1") String name1,
                                             @RequestParam("name2") String name2, @RequestParam("name3") String name3, @RequestParam("name4") String name4,
                                               @RequestParam("name5") String name5, @RequestParam("waterId") String waterId, @RequestParam("volume") String volume){
        Map<String,Object> map = recordSpectrophotometricService.selectBasicSpectrophotometric(formName, type, name1, name2, name3, name4, name5, waterId, volume);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, map);
    }

    /**
     * 记录——分光光度法检测铝、铁、氨、亚硝酸盐原始记录 数据表导出
     * @param recordSpectrophotometric 需要导出的数据列表
     * @return 返回相应数据
     * @throws IOException 异常
     */
    @ApiOperation("列表导出")
    @PostMapping(value = "/download-word")
    public Result downloadWordRecordSpectrophotometric(@RequestBody RecordSpectrophotometric recordSpectrophotometric) throws IOException  {
        recordSpectrophotometricService.downloadRecordSpectrophotometric(recordSpectrophotometric);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }



}

